package com.hsy.commonsdk.app;

import android.text.TextUtils;
import com.blankj.utilcode.util.SPUtils;

import java.util.Set;

public class AppConstant {

    private static volatile AppConstant singleton;

    private AppConstant() {
    }

    public static AppConstant getInstance() {
        if (singleton == null) {
            synchronized (AppConstant.class) {
                if (singleton == null) {
                    singleton = new AppConstant();
                }
            }
        }
        return singleton;
    }

    SPUtils spUtils;

    public void init(String packageName) {
        spUtils = new SPUtils(packageName);
    }

    public void setSpValue(@SPCode String spCode, String value) {
        spUtils.put(spCode, value);
    }

    public void setSpValue(@SPCode String spCode, boolean value) {
        spUtils.put(spCode, value);
    }

    public void setSpValue(@SPCode String spCode, Set<String> value) {
        spUtils.put(spCode, value);
    }

    public String getUserName() {
        return spUtils.getString(SPCode.USER_NAME);
    }

    public String getUserPwd() {
        return spUtils.getString(SPCode.USER_PWD);
    }

    public String getUserToken() {
        return spUtils.getString(SPCode.USER_TOKEN);
    }

    public boolean isLogin() {
        if (TextUtils.isEmpty(getUserName()) | TextUtils.isEmpty(getUserPwd()) | TextUtils.isEmpty(getUserToken()))
            return false;
        return true;
    }


}